/*
** gauche_droite.c for zappy in /home/guidet_m/TECK2/projets/zappy/server_zappy
** 
** Made by michael guidet
** Login   <guidet_m@epitech.net>
** 
** Started on  Mon Jul  4 15:15:13 2011 michael guidet
** Last update Mon Jul 11 10:14:42 2011 michael guidet
*/

#include "server.h"

void	action_droite(t_fd *fd, t_env *e, char *cmd)
{
  t_fd	*tmp;
  int	pos;
  char	cmd2[BUF_SIZE];

  printf("%sDrone %d %s Execute %s%s\n", PURPLE, fd->pl->id,
	 fd->pl->team, cmd, DEFAUT);
  fd->wait = -1;
  fd->idaction = -1;
  if (fd->pl->look_at == NORD)
    fd->pl->look_at = EST;
  else if (fd->pl->look_at == SUD)
    fd->pl->look_at = OUEST;
  else if (fd->pl->look_at == EST)
    fd->pl->look_at = SUD;
  else if (fd->pl->look_at == OUEST)
    fd->pl->look_at = NORD;
  add_string_to_list(&fd->send_list, "ok\n");
  pos = (fd->pl->look_at == NORD) ? 1 : (fd->pl->look_at == EST)
    ? 2 : (fd->pl->look_at == SUD) ? 3 : 4;
  sprintf(cmd2, "ppo %d %d %d %d\n", fd->pl->id,
	  fd->pl->x, fd->pl->y, pos);
  for (tmp = e->fd; tmp; tmp = tmp->next)
    if (tmp->type == GRAPH)
      add_string_to_list(&tmp->send_list, cmd2);
}

void	action_gauche(t_fd *fd, t_env *e, char *cmd)
{
  t_fd	*tmp;
  int	pos;
  char	cmd2[BUF_SIZE];

  printf("%sDrone %d %s Execute %s%s\n", PURPLE, fd->pl->id,
	 fd->pl->team, cmd, DEFAUT);
  fd->wait = -1;
  fd->idaction = -1;
  if (fd->pl->look_at == NORD)
    fd->pl->look_at = OUEST;
  else if (fd->pl->look_at == SUD)
    fd->pl->look_at = EST;
  else if (fd->pl->look_at == EST)
    fd->pl->look_at = NORD;
  else if (fd->pl->look_at == OUEST)
    fd->pl->look_at = SUD;
  add_string_to_list(&fd->send_list, "ok\n");
  pos = (fd->pl->look_at == NORD) ? 1 : (fd->pl->look_at == EST)
    ? 2 : (fd->pl->look_at == SUD) ? 3 : 4;
  sprintf(cmd2, "ppo %d %d %d %d\n", fd->pl->id,
	  fd->pl->x, fd->pl->y, pos);
  for (tmp = e->fd; tmp; tmp = tmp->next)
    if (tmp->type == GRAPH)
      add_string_to_list(&tmp->send_list, cmd2);
}
